package com.goldcn.util;

import com.goldcn.common.exception.ServiceException;
import com.goldcn.enumeration.ErrorCodeEnum;
import com.goldcn.enumeration.PlatformEnum;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * Created by Administrator on 2016/9/1.
 */
public class CommonTools {

    private static final String ErrorCode="ERROR_GCN99CLOUD_";

    public static ServiceException createException(ErrorCodeEnum errorCodeEnum) {
        return new ServiceException(errorCodeEnum.getErrorMsg(),
                ErrorCode + errorCodeEnum.getErrorCode());
    }

    public static ServiceException createException(ErrorCodeEnum errorCodeEnum,String info) {
        return new ServiceException(errorCodeEnum.getErrorMsg()+":"+info,
                ErrorCode + errorCodeEnum.getErrorCode());
    }

    public static String createBusinessBillsNo(PlatformEnum platform,int billsType){
        StringBuffer billsNo=new StringBuffer();
        switch(platform){
            case O2O:
                billsNo.append("100");
                break;
            case B2B:
                billsNo.append("200");
                break;
            default:
                return billsNo.toString();
        }
        switch (billsType){
            case 0://订单
                billsNo.append("10");
                break;
            case 1://付款单
                billsNo.append("20");
                break;
            case 2://付款子单
                billsNo.append("30");
                break;
            default:
                return "";
        }

        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String date=formatter.format(new Date());
        billsNo.append(date);
        Random random=new Random();
        billsNo.append(random.nextInt(8999)+1000+"");
        return billsNo.toString();
    }

}
